﻿#include "FITKAcousticsVTKViewAdaptorSensor.h"
#include "FITKAcousticsVTKGraphObjectSensor.h"

#include "FITK_Component/FITKAcousticsModel/FITKAcousticsSensors.h"

namespace Exchange
{
    bool FITKAcousticsVTKViewAdaptorSensor::update()
    {
        if (_dataObj == nullptr)return false;

        if (m_needUpdate == false) {
            return (m_outputData != nullptr);
        }

        Acoustics::FITKAcousticsSensors* data = dynamic_cast<Acoustics::FITKAcousticsSensors*>(_dataObj);
        if (!data) {
            return false;
        }

        // If output is exist, then delete it and create a new one.
        if (m_outputData) {
            delete m_outputData;
            m_outputData = nullptr;
        }

        // The output data object for view
        FITKAcousticsVTKGraphObjectSensor* outputData = new FITKAcousticsVTKGraphObjectSensor(data);

        m_needUpdate = false;

        // If the actor count is 0, then this graph object is invalid.
        if (outputData->getActorCount() == 0) {
            delete outputData;
            return false;
        }

        m_outputData = outputData;

        return true;
    }
}